package com.eogo.user.web;

import com.eogo.user.pojo.User;
import com.eogo.user.service.UserService;
import com.eogo.user.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "用户管理")
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value="查询用户列表", notes="")
    @GetMapping("queryUserList")
    public ResponseEntity<List<User>>  queryUserList(){
        UserVo userVo = new UserVo();
        List<User> list = userService.queryUserList(userVo);
        return ResponseEntity.ok(list);
    }

    @ApiOperation(value = "注册用户" , notes = "")
    @PostMapping("insertUser")
    public ResponseEntity<Void> insertUser(@ApiParam("用户实体对象")User user){
        userService.insertUser(user);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    @ApiOperation(value = "修改用户" , notes = "")
    @PutMapping("updateUser")
    public ResponseEntity<Void> updateUser(@ApiParam("用户实体对象") User user){
        userService.updateUser(user);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    @ApiOperation(value = "根据主键ID查询用户" , notes = "")
    @GetMapping("queryUserById")
    public ResponseEntity<User> queryUserById(@ApiParam("主键ID")@RequestParam(name = "id" ) Long id){
        User user = userService.queryUserById(id);
        return ResponseEntity.ok(user);
    }

    @ApiOperation(value = "根据主键ID删除用户" , notes = "")
    @DeleteMapping("deleteUserById")
    public ResponseEntity<Void> deleteUserById(@ApiParam("主键ID")@RequestParam(name = "id" ) Long id){
         userService.deleteUserById(id);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

}
